package 代码随想录.双指针法;



public class _5反转链表 {
    /**
     * 206. 反转链表
     * https://leetcode.cn/problems/reverse-linked-list/
     * 给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
     */
    class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }
    public ListNode reverseList(ListNode head) {
        ListNode newhead = null;
        while (head!=null){
            ListNode p = head.next;
            head.next = newhead;
            newhead = head;
            head = p;
        }
        return newhead;
    }
}
